package com.flyone.herbal.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.flyone.herbal.common.ErrorCode;
import com.flyone.herbal.exception.BusinessException;
import com.flyone.herbal.mapper.PostThumbMapper;
import com.flyone.herbal.model.entity.Post;
import com.flyone.herbal.model.entity.PostThumb;
import com.flyone.herbal.model.entity.User;
import com.flyone.herbal.service.PostService;
import com.flyone.herbal.service.PostThumbService;
import com.flyone.herbal.service.PostViewService;
import org.springframework.aop.framework.AopContext;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * 帖子点赞服务实现
 */
@Service
public class PostViewServiceImpl implements PostViewService {

    @Resource
    private PostService postService;

    /**
     * 点赞
     *
     * @param postId
     * @param loginUser
     * @return
     */
    @Override
    public int doPostView(long postId, User loginUser) {
        Post post = postService.getById(postId);
        int viewNum = post.getViewNum() + 1;
        post.setViewNum(viewNum);
        postService.updateById(post);
        return viewNum;
    }
}




